home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1994 September / macformat-004.iso / Shareware City / Graphics / VideoToolbox ƒ / VideoToolboxSources / MacMemory.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-07  |  1.8 KB  |  39 lines  |  [TEXT/KAHL]

  1. /*
  2. MacMemory.h
  3.  
  4. Redefines all the Standard C memory allocation functions to be implemented
  5. directly as calls to the Macintosh Memory Manager.
  6.  
  7. You use MacMemory.h by adding the line "#include <MacMemory.h>" either to your 
  8. THINK C project prefix or to some header file that you include in all your files.
  9.  
  10. Symantec is rather apologetic about the poor performance of their memory
  11. manager, which implements the Standard C library functions free, malloc, calloc,
  12. and realloc (THINK Reference:Standard Libraries:"Allocating Memory"). The THINK
  13. C memory manager requests 15 KB (or larger) chunks of memory from Apple's memory
  14. manager and then doles out this memory to your program in whatever size pieces
  15. you request. The problem is that the THINK C memory manager isn't smart enough
  16. to recombine pieces you return to it via free, so programs (like Quest)
  17. that do a lot of allocation and freeing end up triggering the THINK C memory
  18. manager to keep asking for new 15KB chunks that eventually use up all free
  19. memory until the program fails for lack of memory. Spuriously eating up free 
  20. memory is called a "memory leak".
  21.  
  22. The benefit of using MacMemory.h is that you will use memory efficiently.
  23. The disadvantage is that it is possible (I haven't checked) that the THINK C
  24. memory manager is much quicker for a series of small allocations. The Apple
  25. Memory Manager is quite slow. E.g. calls to NewGWorld take 0.2 s on a Mac II,
  26. and my impression is that most of this time is taken up allocating memory.
  27.  
  28. HISTORY:
  29. 3/5/94 dgp wrote it.
  30. */
  31. #pragma once    // Only include this once.
  32.  
  33. void *MacRealloc(void *oldPtr,size_t size);
  34.  
  35. #define free(ptr) DisposePtr((Ptr)(ptr))
  36. #define malloc(bytes) (void *)NewPtr(bytes)
  37. #define calloc(n,size) (void *)NewPtrClear((size_t)(n)*(size))
  38. #define realloc(ptr,size) MacRealloc(ptr,size)
  39.